/*
 * Copyright 2010-2012 Susanta Tewari. <freecode4susant@users.sourceforge.net>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
* ComGLHoodOView.java
*
* Created on November 15, 2007, 7:51 PM
 */
package gui.genomemap.view.outputView;

import genomemap.worker.LHood;

import gui.genomemap.event.event.WorkerOutputEvent;
import gui.genomemap.outputModel.ComJLHoodOModel;
import gui.genomemap.view.outputView.options.ComJLHoodOOptions;

import javautil.collections.ArrayUtil;
import javautil.io.IOUtil;

import java.text.DecimalFormat;

import javax.swing.JDialog;
import javax.swing.SwingUtilities;

/**
 *
 * @author  stewari1
 */
public class ComJLHoodOView extends OutputView {

    /** Field description */
    private final ComJLHoodOOptions optionsDialog = new ComJLHoodOOptions(new javax.swing.JFrame(),
                                                        false);


    // Variables declaration - do not modify//GEN-BEGIN:variables

    /** Field description */
    private javax.swing.JLabel JLabel4;

    /** Field description */
    private javax.swing.JLabel JLabel5;

    /** Field description */
    private javax.swing.JLabel glHood_JLabel;

    /** Field description */
    private javax.swing.JLabel jLabel1;

    /** Field description */
    private javax.swing.JLabel jLabel2;

    /** Field description */
    private javax.swing.JLabel lhood_JLabel;

    /** Field description */
    private javax.swing.JLabel plHood_JLabel;

    /** Field description */
    private javax.swing.JTextField probeSpacing_JTextField;


    // End of variables declaration//GEN-END:variables

    /** Creates new form ComGLHoodOView */
    public ComJLHoodOView() {

        initComponents();
        optionsDialog.setOutputView(this);
    }

    /**
     * This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */


    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1                 = new javax.swing.JLabel();
        lhood_JLabel            = new javax.swing.JLabel();
        jLabel2                 = new javax.swing.JLabel();
        probeSpacing_JTextField = new javax.swing.JTextField();
        JLabel4                 = new javax.swing.JLabel();
        JLabel5                 = new javax.swing.JLabel();
        plHood_JLabel           = new javax.swing.JLabel();
        glHood_JLabel           = new javax.swing.JLabel();

        jLabel1.setText("The Computed Joint Likelihood is :  ");
        jLabel2.setText("The Estimated Probe Spacings are: ");
        JLabel4.setText("The Physical Map COntribution (Log-likelihood): ");
        JLabel5.setText("The Genetic Map COntribution (Log-likelihood): ");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);

        this.setLayout(layout);
        layout.setHorizontalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel1).addComponent(JLabel4))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(plHood_JLabel).addComponent(lhood_JLabel)))
                                        .addGroup(layout.createSequentialGroup()
                                            .addComponent(jLabel2).addGap(10, 10, 10)
                                                .addComponent(probeSpacing_JTextField,
                                                    javax.swing.GroupLayout.PREFERRED_SIZE, 177,
                                                        javax.swing.GroupLayout.PREFERRED_SIZE))
                                                            .addGroup(layout.createSequentialGroup()
                                                                .addComponent(JLabel5)
                                                                    .addPreferredGap(javax.swing
                                                                        .LayoutStyle
                                                                            .ComponentPlacement
                                                                                .UNRELATED)
                                                                                    .addComponent(glHood_JLabel)))
                                                                                        .addContainerGap(281,
                                                                                            Short.MAX_VALUE)));
        layout.setVerticalGroup(layout
            .createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup().addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1).addComponent(lhood_JLabel)).addGap(7, 7, 7)
                        .addGroup(layout
                            .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(JLabel4).addComponent(plHood_JLabel))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(layout
                                    .createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(JLabel5).addComponent(glHood_JLabel))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement
                                            .RELATED)
                                                .addGroup(layout
                                                    .createParallelGroup(javax.swing.GroupLayout
                                                        .Alignment.BASELINE).addComponent(jLabel2)
                                                            .addComponent(probeSpacing_JTextField,
                                                                javax.swing.GroupLayout
                                                                    .PREFERRED_SIZE, javax.swing
                                                                        .GroupLayout
                                                                            .DEFAULT_SIZE, javax
                                                                                .swing.GroupLayout
                                                                                    .PREFERRED_SIZE))
                                                                                        .addGap(22,
                                                                                            22,
                                                                                            22)));

    }    // </editor-fold>//GEN-END:initComponents

    @Override
    public void refresh() {

        if (getOutputModel() == null) {

            lhood_JLabel.setText("");

            return;
        }

        ComJLHoodOModel comJLHoodOModel = (ComJLHoodOModel) getOutputModel();

        lhood_JLabel.setText("" + comJLHoodOModel.getLHood());
        plHood_JLabel.setText("" + comJLHoodOModel.getPLogLikeliHood());
        glHood_JLabel.setText("" + comJLHoodOModel.getGLogLikeliHood());
        probeSpacing_JTextField.setText(
            IOUtil.toString(
                ArrayUtil.getDoubleArray(comJLHoodOModel.getProbeSpacing()), ",",
                new DecimalFormat("0.####")));
        optionsDialog.setOptions(comJLHoodOModel);
    }

    @Override
    public JDialog getOptionsDialog() {
        return optionsDialog;
    }

    @Override
    public void doComJLHoodOutput(WorkerOutputEvent e) {


        // the view(OutputView) is listening from the working process now
        // launch runnables on swing thread according to the runtime display options set
        // in your output model which is the same instance the process worker has.
        // ontain information on the worker using e.getSource().. this case it will be an LHood object
        LHood lhood = (LHood) e.getSource();


        // update according to the options set
        Runnable runnable = new Runnable() {
            public void run() {}
        };

        SwingUtilities.invokeLater(runnable);
    }
}
